<?php
/*
+ ---------------------------------------------------------------------- +
| e107Shop - An e-commerce plugin for the e107 content management system |
|                                                                        |
| ByOrder Europe 2007-2009                                               |
| http://e107shop.com                                                    |
| pbielen@gmail.com                                                      |
|                                                                        |
| Released under the terms and conditions of the LGPL                    |
+ ---------------------------------------------------------------------- +
*/

//check it the file is called within e107, if not get out !
if (!defined('e107_INIT')) { exit; }

// Load the database table-names
require("db_names.php");

// Name of the plugin's folder -------------------------------------------------------------------------------------
$eplug_folder = "e107shop";
include_lan(e_PLUGIN.$eplug_folder."/languages/".e_LANGUAGE."_plugin.php");
    
// Plugin info -------------------------------------------------------------------------------------------------------
$eplug_name = 'e107Shop';
$eplug_version = '1.2.21';
$eplug_author = 'Patrick Bielen';
$eplug_url = 'http://e107shop.com';
$eplug_email = 'pbielen@gmail.com';
$eplug_description = e107shop_plugin_desc;
$eplug_compatible = 'e107v0.7+';
$eplug_readme = '';
$eplug_latest = False; //Show reported threads in admin (use latest.php)
$eplug_status = False; //Show post count in admin (use status.php)

// Name of menu item for plugin ----------------------------------------------------------------------------------
$eplug_menu_name = "e107Shop";
    
// Name of the admin configuration file --------------------------------------------------------------------------
$eplug_conffile = "admin/admin_e107shop_index.php";
    
// Icon image and caption text ------------------------------------------------------------------------------------
$eplug_icon       = $eplug_folder."/e107shop_32.png";
$eplug_icon_small = $eplug_folder."/e107shop_16.png";
$eplug_caption    = 'Configure e107Shop';
    
// List of preferences -----------------------------------------------------------------------------------------------
$eplug_prefs = array();
    
// List of table names -----------------------------------------------------------------------------------------------
$eplug_table_names = array(
    $e107shop_db_name['cart'], $e107shop_db_name['categories'], $e107shop_db_name['category_matrix'], 
    $e107shop_db_name['coupons'], $e107shop_db_name['customer_information'], $e107shop_db_name['gateways'], 
    $e107shop_db_name['orders'], $e107shop_db_name['postage'], $e107shop_db_name['product_options'], 
    $e107shop_db_name['products'], $e107shop_db_name['settings'], $e107shop_db_name['custom'], 
    $e107shop_db_name['downloads'], $e107shop_db_name['validate'], $e107shop_db_name['pp_payment_info'], 
    $e107shop_db_name['advanced']);

// List of sql requests to create tables -----------------------------------------------------------------------------
$eplug_tables = array(
"CREATE TABLE `".MPREFIX.$e107shop_db_name['cart']."` (
  `lineID` int(11) NOT NULL auto_increment,
  `cart_ID` varchar(255) NOT NULL default '',
  `productID` varchar(255) NOT NULL default '',
  `quantity` varchar(255) NOT NULL default '',
  `option` varchar(255) NOT NULL default '',
  `cart_time` int(11) NOT NULL default '0',
  `order_number` varchar(255) NOT NULL default '',
  `field1` varchar(255) NOT NULL default '',
  `field2` varchar(255) NOT NULL default '',
  `field3` varchar(255) NOT NULL default '',
  `field4` varchar(255) NOT NULL default '',
  `field5` varchar(255) NOT NULL default '',
  `field6` varchar(255) NOT NULL default '',
  `field7` varchar(255) NOT NULL default '',
  `field8` varchar(255) NOT NULL default '',
  `field9` varchar(255) NOT NULL default '',
  `field10` varchar(255) NOT NULL default '',
  `field11` varchar(255) NOT NULL default '',
  `field12` varchar(255) NOT NULL default '',
  `field13` varchar(255) NOT NULL default '',
  `field14` varchar(255) NOT NULL default '',
  `field15` varchar(255) NOT NULL default '',
  `field16` varchar(255) NOT NULL default '',
  `field17` varchar(255) NOT NULL default '',
  `field18` varchar(255) NOT NULL default '',
  `field19` varchar(255) NOT NULL default '',
  `field20` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`lineID`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['categories']."` (
  `catId` int(11) NOT NULL auto_increment,
  `catName` varchar(250) default NULL,
  `catDesc` varchar(250) default NULL,
  `parid` varchar(255) default NULL,
  `catimg` varchar(255) default NULL,
  `catord` int(5) default '1',
  `active` int(11) default '1',
  `items` int(1) default '2',
  `category_class` int(11) NOT NULL,
  `category_order_class` int(11) NOT NULL,  
  PRIMARY KEY (`catId`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['category_matrix']."` (
  `product_id` int(11) NOT NULL default '0',
  `category_id` int(11) NOT NULL default '0',
  PRIMARY KEY (`product_id`, `category_id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['coupons']."` (
  `coupon_name` varchar(255) NOT NULL default '',
  `coupon_code` varchar(255) NOT NULL default '',
  `coupon_expiry_date` int(50) default NULL,
  `coupon_used_x_times` int(11) NOT NULL default '0',
  `xvalid_for_uses` varchar(255) NOT NULL default '',
  `coupon_discount_amount` decimal(10,2) NOT NULL default '0',
  `coupon_discount_type` varchar(255) NOT NULL default ''
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['customer_information']."` (
  `ID` int(11) NOT NULL auto_increment,
  `username` varchar(255) NOT NULL default '',
  `customer_name` varchar(255) NOT NULL default '',
  `customer_last_name` varchar(255) NOT NULL default '',
  `customer_email` varchar(255) NOT NULL default '',
  `customer_address1` varchar(255) NOT NULL default '',
  `customer_address2` varchar(255) default NULL,
  `customer_city` varchar(255) NOT NULL default '',
  `customer_state` varchar(255) NOT NULL default '',
  `customer_country` varchar(255) NOT NULL default '',
  `customer_region` varchar(255) default NULL,
  `customer_zip` varchar(255) NOT NULL default '',
  `orderID` varchar(255) NOT NULL default '',
  PRIMARY KEY (`ID`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['gateways']."` (
  `ID` int(11) NOT NULL auto_increment,
  `identifier` varchar(255) NOT NULL default '',
  `account` varchar(255) NOT NULL default '',
  `field1` varchar(255) NOT NULL default '',
  `field2` varchar(255) NOT NULL default '',
  `field3` varchar(255) NOT NULL default '',
  `field4` varchar(255) NOT NULL default '',
  `field5` varchar(255) NOT NULL default '',
  `field6` varchar(255) NOT NULL default '',
  `field7` varchar(255) NOT NULL default '',
  `field8` varchar(255) NOT NULL default '',
  `gateway_class` INT(11) NOT NULL,
  `active` int(11) NOT NULL default '0',
  UNIQUE KEY ID (`ID`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"INSERT INTO `".MPREFIX.$e107shop_db_name['gateways']."` (
    `ID`, `identifier`, `account`, `field1`, `field2`,
    `field3`, `field4`, `field5`, `field6`, `field7`, 
    `field8`, `gateway_class`, `active`) VALUES (NULL , 'ideal', 'UserName', 
    'https://internetkassa.abnamro.nl/ncol/test/orderstandard.asp', 
    'sha1StringForEncryption', 
    '0', '', '', '', '', '', 0, '0');",
"INSERT INTO `".MPREFIX.$e107shop_db_name['gateways']."` (
    `ID` , `identifier` , `account` , `field1` , `field2` , 
    `field3` , `field4` , `field5` , `field6` , `field7` , 
    `field8` , `gateway_class`, `active`) VALUES ('4', 'ideal_lite', 
    'ideal_id', 'url to your ideal api', 'hash key', '0', 
    '0', '', '', '', '', 0, '0');",
"INSERT INTO `".MPREFIX.$e107shop_db_name['gateways']."` (
    `ID`, `identifier`, `account`, `field1`, `field2`,
    `field3`, `field4`, `field5`, `field6`, `field7`, 
    `field8`, `gateway_class`, `active`) VALUES (NULL , 'offline', '', '', '', 
    '0', '', '', '', '', '', 0, '1');",
"INSERT INTO `".MPREFIX.$e107shop_db_name['gateways']."` (
    `ID`, `identifier`, `account`, `field1`, `field2`,
    `field3`, `field4`, `field5`, `field6`, `field7`, 
    `field8`, `gateway_class`, `active`) VALUES (NULL , 'paypal', 'PayPal_ID', 
    'https://www.sandbox.paypal.com/cgi-bin/webscr', '', 
    '0', '', '', '', '', '', 0, '0');",
"INSERT INTO `".MPREFIX.$e107shop_db_name['gateways']."` (
    `ID`, `identifier`, `account`, `field1`, `field2`,
    `field3`, `field4`, `field5`, `field6`, `field7`, 
    `field8`, `gateway_class`, `active`) VALUES (NULL , 'payson', 'PaySon_ID', 
    'https://www.payson.se/testagent/default.aspx', 'MD5Key', 
    '', '', 'Email', '1', '', '', 0, '0');",
"INSERT INTO `".MPREFIX.$e107shop_db_name['gateways']."` (
    `ID`, `identifier`, `account`, `field1`, `field2`,
    `field3`, `field4`, `field5`, `field6`, `field7`,
    `field8`, `gateway_class`, `active`) VALUES (NULL , 'saman', 'Saman MID',
    'https://acquirer.sb24.com/CardServices/controller', 'http://yourdomain.ext/images/putyourlogourlhere.jpg', '0', '', '', '', '', '', 0, '0');",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['orders']."` (
  `lineID` int(11) NOT NULL auto_increment,
  `cart_ID` varchar(255) NOT NULL default '',
  `productID` varchar(255) NOT NULL default '',
  `quantity` varchar(255) NOT NULL default '',
  `option` varchar(255) NOT NULL default '',
  `order_number` varchar(255) NOT NULL default '',
  `status` varchar(255) NOT NULL default '',
  `last_mod` varchar(255) NOT NULL default '',
  `gateway` varchar(255) NOT NULL default '',
  `theuser` varchar(255) NOT NULL default '',
  `cust_region` varchar(255) NOT NULL default '',
  `coupon` varchar(255) NOT NULL default '',
  `sale_price` varchar(255) NOT NULL default '',
  `field1` varchar(255) NOT NULL default '',
  `field2` varchar(255) NOT NULL default '',
  `field3` varchar(255) NOT NULL default '',
  `field4` varchar(255) NOT NULL default '',
  `field5` varchar(255) NOT NULL default '',
  `field6` varchar(255) NOT NULL default '',
  `field7` varchar(255) NOT NULL default '',
  `field8` varchar(255) NOT NULL default '',
  `field9` varchar(255) NOT NULL default '',
  `field10` varchar(255) NOT NULL default '',
  `field11` varchar(255) NOT NULL default '',
  `field12` varchar(255) NOT NULL default '',
  `field13` varchar(255) NOT NULL default '',
  `field14` varchar(255) NOT NULL default '',
  `field15` varchar(255) NOT NULL default '',
  `field16` varchar(255) NOT NULL default '',
  `field17` varchar(255) NOT NULL default '',
  `field18` varchar(255) NOT NULL default '',
  `field19` varchar(255) NOT NULL default '',
  `field20` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`lineID`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['postage']."` (
  `region_id` int(11) NOT NULL auto_increment,
  `postage_region` varchar(255) NOT NULL default '',
  `postage_price` varchar(255) NOT NULL default '',
  `extra` varchar(255) NOT NULL default '',
  PRIMARY KEY (`region_id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['product_options']."` (
  `ID` int(11) NOT NULL auto_increment,
  `itemid` varchar(255) NOT NULL default '',
  `optname` varchar(255) NOT NULL default '',
  `optval` varchar(255) NOT NULL default '',
  `opter` varchar(255) NOT NULL default '',
  `option_group` varchar(255) NOT NULL default '',
  UNIQUE KEY ID (`ID`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['products']."` (
  `ID` int(11) NOT NULL auto_increment,
  `large_image` varchar(255) NOT NULL default '',
  `product_price` varchar(255) NOT NULL default '',
  `description` longtext NOT NULL,
  `product_name` varchar(255) NOT NULL default '',
  `active` int(11) NOT NULL default '0',
  `postage_price` varchar(255) NOT NULL default '',
  `stock_on_hand` int(10) NOT NULL default '0',
  `downloadable` varchar(255) NOT NULL default '',
  `download_file` varchar(255) NOT NULL default '',
  `special_price` varchar(255) NOT NULL default '',
  `product_tier` varchar(255) NOT NULL default '',
  `date_added` varchar(255) NOT NULL default '',
  `function_page` varchar(255) NOT NULL default '',
  `customize` int(11) NOT NULL default '0',
  `cust_cat` int(11) NOT NULL default '0',
  `fname_1` VARCHAR( 255 ) NOT NULL default '',
  `fname_2` VARCHAR( 255 ) NOT NULL default '',
  `fname_3` VARCHAR( 255 ) NOT NULL default '',
  `fname_4` VARCHAR( 255 ) NOT NULL default '',
  `fname_5` VARCHAR( 255 ) NOT NULL default '',    
  `fname_6` VARCHAR( 255 ) NOT NULL default '',
  `fname_7` VARCHAR( 255 ) NOT NULL default '', 
  `fname_8` VARCHAR( 255 ) NOT NULL default '',
  `fname_9` VARCHAR( 255 ) NOT NULL default '',
  `fname_10` VARCHAR( 255 ) NOT NULL default '',
  `fname_11` VARCHAR( 255 ) NOT NULL default '',
  `fname_12` VARCHAR( 255 ) NOT NULL default '',
  `fname_13` VARCHAR( 255 ) NOT NULL default '',
  `fname_14` VARCHAR( 255 ) NOT NULL default '',
  `fname_15` VARCHAR( 255 ) NOT NULL default '',
  `fname_16` VARCHAR( 255 ) NOT NULL default '',
  `fname_17` VARCHAR( 255 ) NOT NULL default '',
  `fname_18` VARCHAR( 255 ) NOT NULL default '',
  `fname_19` VARCHAR( 255 ) NOT NULL default '',
  `fname_20` VARCHAR( 255 ) NOT NULL default '',
  `thumb_only` int( 11 ) NOT NULL default '0',
  PRIMARY KEY (`ID`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['settings']."` (
  `postage_method` varchar(255) default NULL,
  `postage_min` decimal(10,2) default NULL,
  `postage_max` decimal(10,2) default NULL,
  `currency` varchar(250) default NULL,
  `customer_must_be_member` varchar(255) default NULL,
  `category_display` varchar(255) default NULL,
  `sell_into_minus_stock` varchar(255) default NULL,
  `warning_level` varchar(255) default NULL,
  `use_coupons` varchar(255) default NULL,
  `tax_inc` varchar(255) NOT NULL default '',
  `tax_rate` varchar(255) default NULL,
  `price_break_yn` varchar(255) default NULL,
  `price_break_point` varchar(255) default NULL,
  `store_name` varchar(255) default 'Online Store',
  `item_display_order` varchar(255) NOT NULL default '',
  `products_per_page` varchar(255) default '10',
  `currency_symbol` varchar(255) NOT NULL default '',
  `orderID` int(20) NOT NULL default '0',
  `order_email` varchar(255) NOT NULL default '',
  `license` varchar(255) NOT NULL default '',
  `download_dir` varchar(255) NOT NULL default '',
  `store_address1` varchar(255) NOT NULL default '',
  `store_address2` varchar(255) NOT NULL default '',
  `store_address3` varchar(255) NOT NULL default '',
  `store_address4` varchar(255) NOT NULL default '',
  `thumbnail_size` varchar(255) default '80'
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"INSERT INTO `".MPREFIX.$e107shop_db_name['settings']."` (item_display_order, products_per_page, thumbnail_size) 
VALUES ('product_price', '10', '80');",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['custom']."` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) default NULL,
  `r_name` varchar(255) default NULL,
  `r_type` varchar(11) default NULL,
  `position` varchar(11) default NULL,
  `content` longtext,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['downloads']."` (
  `id` int(11) NOT NULL auto_increment,
  `order_number` varchar(255) default NULL,
  `download_file` varchar(255) default NULL,
  `USERNAME` varchar(255) default NULL,
  `expirydate` varchar(255) default NULL,
  `downloaded` int(11) Not Null,
  `download_limit` int(11) Not Null,
  `productID` int(11) Not Null,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['validate']."` (
  `vald_fname` int(11) NOT NULL default '1',
  `vald_lname` int(11) NOT NULL default '1',
  `vald_email` int(11) NOT NULL default '1',
  `vald_addr1` int(11) NOT NULL default '1',
  `vald_city` int(11) NOT NULL default '1',
  `vald_state` int(11) NOT NULL default '1',
  `vald_count` int(11) NOT NULL default '1',
  `vald_region` int(11) NOT NULL default '1',
  `vald_zip` int(11) NOT NULL default '1'
  ) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['pp_payment_info']."` (
  `firstname` varchar(100) NOT NULL default '',
  `lastname` varchar(100) NOT NULL default '',
  `buyer_email` varchar(100) NOT NULL default '',
  `street` varchar(100) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `state` char(3) NOT NULL default '',
  `zipcode` varchar(11) NOT NULL default '',
  `memo` varchar(255) default NULL,
  `itemname` varchar(255) default NULL,
  `itemnumber` varchar(50) default NULL,
  `os0` varchar(20) default NULL,
  `on0` varchar(50) default NULL,
  `os1` varchar(20) default NULL,
  `on1` varchar(50) default NULL,
  `quantity` char(3) default NULL,
  `paymentdate` varchar(50) NOT NULL default '',
  `paymenttype` varchar(10) NOT NULL default '',
  `txnid` varchar(30) NOT NULL default '',
  `mc_gross` varchar(6) NOT NULL default '',
  `mc_fee` varchar(5) NOT NULL default '',
  `paymentstatus` varchar(15) NOT NULL default '',
  `pendingreason` varchar(10) default NULL,
  `txntype` varchar(10) NOT NULL default '',
  `tax` varchar(10) default NULL,
  `mc_currency` varchar(5) NOT NULL default '',
  `reasoncode` varchar(20) NOT NULL default '',
  `custom` varchar(255) NOT NULL default '',
  `country` varchar(20) NOT NULL default '',
  `datecreation` date NOT NULL default '0000-00-00'
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
"CREATE TABLE `".MPREFIX.$e107shop_db_name['advanced']."` (
    `tblkey` VARCHAR(100) NOT NULL, 
    `tblvalue` VARCHAR(100) NULL) 
    ENGINE = MyISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;",
"INSERT INTO `".MPREFIX.$e107shop_db_name['advanced']."` (tblkey, tblvalue) VALUES 
('catstyle_forum_border','1px solid black'), 
('catstyle_forum_halign', 'center'), 
('catstyle_forum_padding', '10px 2% 10px 2%'), 
('catstyle_forum_valign', 'middle'), 
('catstyle_name_bold','on'), 
('catstyle_pcs_per_row','3'), 
('catstyle_thumb_border','1px solid black'), 
('catstyle_thumb_noscale','on'), 
('catstyle_thumb_only','off'), 
('catstyle_thumb_width','150'), 
('invoice_bottom_line1', '".e107shop_plugin_invbot1."'), 
('invoice_bottom_line2', '".e107shop_plugin_invbot2."'), 
('invoice_bottom_line3', '".e107shop_plugin_invbot3."'), 
('invoice_bottom_line4', '".e107shop_plugin_invbot4."'), 
('invoice_bottom_line5', '".e107shop_plugin_invbot5."'),
('invoice_bottom_line6', '".e107shop_plugin_invbot6."'),
('invoice_bottom_line7', '".e107shop_plugin_invbot7."'),
('invoice_offline_line1', '".e107shop_plugin_offline1."'), 
('invoice_offline_line2', '".e107shop_plugin_offline2."'), 
('invoice_offline_line3', '".e107shop_plugin_offline3."'), 
('invoice_offline_line4', '".e107shop_plugin_offline4."'), 
('invoice_offline_line5', '".e107shop_plugin_offline5."'),
('invoice_offline_line6', '".e107shop_plugin_offline6."'), 
('product_list_admin', 'on'), 
('product_list_admin_delete', 'deactivate'), 
('product_list_align_picture', 'center'),
('product_list_align_name', 'left'),
('product_list_align_price', 'center'),
('product_list_align_quant', 'center'),
('product_list_align_action', 'center'),
('product_list_view', '5');"
);
    
// Create a link in main menu (yes=TRUE, no=FALSE) -------------------------------------------------------------
$eplug_link = TRUE;
$eplug_link_name = "e107Shop";
$eplug_link_url = e_PLUGIN.$eplug_folder.'/index.php';
    
$eplug_done = e107shop_plugin_installed;
    
$upgrade_alter_tables = array(
    "INSERT INTO `".MPREFIX."e107shop_gateways` (
    `ID`, `identifier`, `account`, `field1`, `field2`,
    `field3`, `field4`, `field5`, `field6`, `field7`, 
    `field8`, `gateway_class`, `active`) VALUES (NULL , 'payson', 'PaySon_ID', 
    'https://www.payson.se/testagent/default.aspx', 'MD5Key', 
    '', '', 'Email', '1', '', '', 0, '0');"
);

// Text to display after plugin successfully installed or upgraded

$eplug_upgrade_done = e107shop_plugin_upgraded;
